<?php
/**
 * 管理中心· 会员管理模块的逻辑处理
 * ============================================================================
 * 版权所有 2017-2020 北京优特世纪科技有限公司，并保留所有权利。
 * 网站地址: http://www.unitewww.com;
 * ============================================================================
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * @since: 1.0
 * @version: 1.0
 **/
namespace Hoteladmin\Model;
use Think\Model;
class UserModel extends Model{
	/**
	 +--------------------------------------------------------------------------
	 * 实现添加（修改）会员信息的功能
	 * @param $type $id 会员ID
	 * @author : XC跃
	 * @date : 2018-09-28
	 +--------------------------------------------------------------------------
	 */
	public function user_add_edit($id){
		//实例化相关表
		$usident = M('user');
		$uvident = M('user_vip');
		//获取系统参数
		$sms = tpCache("sMes.cheng");
		//P($sres);
		if(''!=$id){

			if(''!=I('post.upwd')){
				$data['us_pwd'] = trim(md5(I('post.upwd')));
			}
			if(''!=I('post.upwds')){
				$data['us_pwds']= trim(md5(I('post.upwds')));
			}
			$data['us_name'] = $uname = trim(I('post.uname'));
			$data['us_phone']= $phone = trim(I('post.phone'));
			$data['us_pid']  = trim(I('post.pid','0'));
			$data['us_sname']= trim(I('post.sname'));
			$data['us_area'] = trim(I('post.area'));
			$data['us_addre']= trim(I('post.addre'));
			$re = $usident->where("`us_uid`='".$id."'")->save($data);
			//记录操作日志
			addLog(session('admin_auth.usname'),'2','2','编辑'.$id.'会员信息');
		}else{
			$vid = $uvident->order('uv_vid desc')->getField('uv_vid');
			//1、添加注册信息
			$data['us_uid']  = $nuid = rand_number();
			$data['us_pid']  = $pid = trim(I('post.pidval'));
			$data['us_name'] = $uname = trim(I('post.uname'));
			$data['us_phone']= $phone = trim(I('post.phone'));
			$data['us_pwd']  = md5('123456');
			$data['us_pwds'] = md5('123456');
			$data['us_atime']= time();
			$data['us_state']= '3';  //1已审核 2锁点 3待激活
			$re = $usident->add($data);
//			$date['uv_uid']  =$nuid;
//			$date['uv_pid']  = trim(I('post.pidval'));
//			$date['uv_vid'] = $vid + 1;
//			$date['uv_lid'] = trim(I('post.lid'));
//			$date['uv_place'] = trim(I('post.place'));
//			$Find = $uvident->where("`uv_lid`='" . $date['uv_lid'] . "'")->find();
//			if($date['uv_place']==  $Find['uv_place']){
//				$res = array('status' => -1, 'msg' => '该位置已存在用户');
//				exit(json_encode($res));
//			}else{
//				$res = $uvident->add($date);
//			}
//			//2、发送手机短信
//			if('1'==$sms && $re>0){
//			    $params['uname']   = $uname;
//			    $params['shopname']= '琴屿飞扬';
//			    sendSms('5', $phone, $params);
//			}
			//3、更新推荐人数
			$usident->where("`us_uid`='".$pid."'")->setInc('us_count',1);
			$usident->where("`us_uid`='".$pid."'")->setInc('us_scount',1);
			do_scount($pid);
			//4、记录操作日志
			addLog(session('admin_auth.usname'),'2','2','注册'.$nuid.'会员信息');
		}
		$re>0?$res=1:$res=0;
		return $res;
	}
}